package logic

import (
	"context"
	"houseRpc/house"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddHouseLogic {
	return &AddHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddHouseLogic) AddHouse(req *types.AddHouseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	addHouse, err := l.svcCtx.HouseRpc.AddHouse(l.ctx, &house.AddHouseRequest{
		UserId: req.UserId,
		Title:  req.Title,
		Ads:    req.Ads,
		Square: req.Square,
		Floor:  req.Floor,
		Price:  float32(req.Price),
		Status: req.Status,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "房源发布成功",
		Code:    200,
		Data:    addHouse,
	}, nil
}
